package src.rmi;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Set;
import src.domain.MailBox;
import src.domain.OutgoingMessage;
import src.domain.PostOffice;
import src.domain.User;
import src.service.MailServerService;

public class ImplementationService extends UnicastRemoteObject implements Service   {

	public ImplementationService() throws RemoteException {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * 
	 */
	private Service service;
	private static final long serialVersionUID = 1L;
	
	public void initService(){
		try {
			this.service = new ImplementationService();
			Naming.rebind("//localhost/ServidorServicio",  service);
		} catch (Exception ex) {
		}
		
	}

	@Override
	public void saveUser(String name, String userName, String country,
			String city, String address, String phoneNumber, boolean active)
			throws RemoteException {
		MailServerService.getInstance().saveUser(name, userName, country, city, address, phoneNumber, active);
		//MailServerService.getInstance().saveUser("", "", "","", "", "",true);
	}

	@Override
	public void updateUser(User user) throws RemoteException {
		MailServerService.getInstance().updateUser(user);
		
	}

	@Override
	public void deleteUser(long idUser) throws RemoteException {
		MailServerService.getInstance().deleteUser(idUser);
		
	}

	@Override
	public Set<User> getAllUsers() throws RemoteException {
		return MailServerService.getInstance().getAllUsers();
	}
	
	@Override
	public Set<User> getUsers(String name) throws RemoteException {
		return MailServerService.getInstance().getUsers(name);
	}

	@Override
	public void savePostOffice(String name,
			Set<MailBox> mailBoxes, Set<PostOffice> trustOffices) {
		MailServerService.getInstance().savePostOffice(name, mailBoxes, trustOffices);
		
	}

	@Override
	public void updatePostOffice(PostOffice postOffice) {
		MailServerService.getInstance().updatePostOffice(postOffice);
		
	}

	@Override
	public void deletePostOffice(long idPostOffice) {
		MailServerService.getInstance().deletePostOffice(idPostOffice);
		
	}

	@Override
	public Set<PostOffice> getAllPostOffices() {
		return MailServerService.getInstance().getAllPostOffices();
	}
	
	@Override
	public Set<PostOffice> getPostOffices(String name) throws RemoteException {
		return MailServerService.getInstance().getPostOffices(name);
	}
	
	@Override
	public Set<PostOffice> getAvailablePostOffices(PostOffice postOffice) throws RemoteException {
		return MailServerService.getInstance().getAvailablePostOffices(postOffice);
	}
	
	@Override
	public  void saveMailBox(String name, String pass, boolean active, User user,Set<PostOffice> postOffices){
		
		MailServerService.getInstance().saveMailBox(name, pass, active, user,postOffices);
		
	}
	
	@Override
	public void updateMailBox(MailBox mailBox){
		MailServerService.getInstance().updateMailBox(mailBox);
	}
	
	@Override
	public void deleteMailBox(long idMailBox){
		MailServerService.getInstance().deleteMailBox(idMailBox);
	}
	
	@Override
	public Set<MailBox> getAllMailBoxes(){
		return MailServerService.getInstance().getAllMailBoxes();
	}
	
	@Override
	public Set<PostOffice> getUnassignedPostOffices(Long idMailBox) {
		return MailServerService.getInstance().getUnassignedPostOffices(idMailBox);
	}

	@Override
	public Set<MailBox> getMailBoxes(String nameMailBox) throws RemoteException {
		return MailServerService.getInstance().getMailBoxes(nameMailBox);
	}

	@Override
	public MailBox getMailBoxByName(String nameMailBox) throws RemoteException {
		return MailServerService.getInstance().getMailBoxByName(nameMailBox);
	}

	@Override
	public User getUserByUserName(String userName) throws RemoteException {
		return MailServerService.getInstance().getUserByUserName(userName);
	}

	@Override
	public PostOffice getPostOfficeByName(String postOfficeName) throws RemoteException {
		return MailServerService.getInstance().getPostOfficeByName(postOfficeName);	
	}
	
	@Override
	public Set<MailBox> getMailBoxesByPostOffice(long idPostOffice){
		return MailServerService.getInstance().getMailBoxesByPostOffice(idPostOffice);
	}

	@Override
	public Set<OutgoingMessage> getOutgoingMessagesByMailBox(long idMailBox)
			throws RemoteException {
		return MailServerService.getInstance().getOutgoingMessagesByMailBox(idMailBox);
	}
	
	@Override
	public Set<MailBox> getMailBoxesByUser(long idUser)throws RemoteException{
		return MailServerService.getInstance().getMailBoxesByUser(idUser);
	}
	
	
}
